package novemberBot.sensor;


/**Ultrasonic responder object sometimes used alone, most of the time acts as a superclass
 * @author Antoine Lennartz*/
public class UsDataResponder {
	/**filters the sensors responders want data from*/
	public enum Sensor{HIGH, LOW};
	
	/**boolean to declare weather the current responder is in need of sensor data*/
	public boolean needsData;
	/**sensor for this responder*/
	public Sensor s;
	
	/**Sensor position from last measurement*/
	private double[] sensorPos = new double[3];
	/**Lock for sensor position*/
	protected Object sPLock = new Object();
	/**Filter for usData for this responder*/
	protected UsFilter filter;
	
	public UsDataResponder(String filterType, Sensor s){
		needsData=false;
		filter=new UsFilter();
		filter.setDefaultFilter(filterType);
		this.s=s;
		
	}
	/**called by UsPoller
	 * @param distnPos - double[]{sensor measurement, x pos, y pos, sensor orientation}*/
	public void newUsData(double[] distnPos){
		filter.newUnfilteredData(distnPos[0]);
		synchronized(sPLock) {
			for(int i=0; i<3; i++){
				sensorPos[i]=distnPos[i+1];
			}
		}
	}
	
	/**Synchronized accessor for sensor position*/
	public double[] getSensorPosition(){
		synchronized(sPLock) {return sensorPos.clone();}
	}
	
	public UsFilter getFilter(){
		return filter;
	}
	
	
	
}
